package com.kfm.pm.exec;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.TreeSet;

public class Exec02 {

    public static void main(String[] args) {
        // 创建一个HashSet，包含一些日期对象（java.util.Date）。编写代码，找到集合中的最早日期和最晚日期。
        HashSet<Date> hashSet = new HashSet<>();
        hashSet.add(new Date(49, 9, 1));
        hashSet.add(new Date(50, 9, 1));
        hashSet.add(new Date(51, 9, 1));
        hashSet.add(new Date(123, 8, 8));
        hashSet.add(new Date(124, 8, 9));
        Date first = new Date();
        Date last = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        Iterator<Date> iterator = hashSet.iterator();
        while (iterator.hasNext()) {
            Date d = iterator.next();
            if (first.compareTo(d) > 0) {
                first = d;
            }
            if (last.compareTo(d) < 0) {
                last = d;
            }
        }
        System.out.println(sdf.format(first));
        System.out.println(sdf.format(last));

//        TreeSet<Date> dateTreeSet = new TreeSet<>(hashSet);
//        Date first = dateTreeSet.first();
//        Date last = dateTreeSet.last();
//
//        System.out.println(sdf.format(first));
//        System.out.println(sdf.format(last));
//        System.out.println(dateTreeSet);
//        dateTreeSet.addAll(hashSet);
    }
}
